<?php
/**
 * 
 * @param $datestr Datetime as a string formattet as "dd-MM-yyyy hh:mm" defaults to now
 * @return zodiacial sign name
 */
function getZodiacSign($datestr = "now")
{
	if ($datestr == "now")
	{
		$datestr = date("d-m-Y H:jj"); // get currrent date, in expected format
		//echo $datestr;
	}
	$matches = Array();
	$datetimePattern = "/^(\d{2})-(\d{2})-((:?\d{2})?\d{2}) (\d{1,2}):(\d{2})$/";
	if(preg_match ( $datetimePattern , $datestr, $matches) == 0)
	{
		throw new Exception("\$datestr ($datestr) does not match pattern: /^(\d{2})-(\d{2})-((:?\d{2})?\d{2}) (\d{1,2}):(\d{2})\$/ ");
	}
	else
	{
		//print_r($matches);
		$day = $matches[1];
		$month = $matches[2];
		
		if ($month > 12 || $month < 1)
			throw new Exception('Month should be 1 to 12.');
		if ($day < 1)
			throw new Exception('Day should be at least 1.');
		switch ($month)	{
			case 1:
				if ($day <=20)	
					return "capricorn";
				else
					return "aquarius";
			break;
			case 2:
				if ($day > 29)
					throw new Exception('In february, day should be no more than 29.');
				if ($day <=18)	
					return "aquarius";
				else
					return "pisces";
			break;
			case 3:
				if ($day > 31)
					throw new Exception('In march, day should be no more than 31.');
				if ($day <=20)
					return "pisces";
				else
					return "aries";
			break;
			case 4:
				if ($day > 30)
					throw new Exception('In april, day should be no more than 30.');
				if ($day <=20)
					return "aries";
				else
					return "taurus";
			break;
			case 5:
				if ($day > 31)
					throw new Exception('In may, day should be no more than 31.');
				if ($day <=21)
					return "taurus";
				else
					return "gemini";
			break;
			case 6:
				if ($day > 30)
					throw new Exception('In june, day should be no more than 30.');
				if ($day <=22)
					return "gemini";
				else
					return "cancer";
			break;
			
			case 7:
				if ($day > 31)
					throw new Exception('In july, day should be no more than 31.');
				if ($day <=22)
					return "cancer";
				else
					return "leo";
			break;
			case 8:
				if ($day > 31)
					throw new Exception('In august, day should be no more than 31.');
				if ($day <=21)
					return "leo";
				else
					return "virgo";
			break;
			case 9:
				if ($day > 30)
					throw new Exception('In september, day should be no more than 30.');
				if ($day <=23)
					return "virgo";
				else
					return "libra";
			break;
			case 10:
				if ($day > 31)
					throw new Exception('In october, day should be no more than 31.');
				if ($day <=23)
					return "libra";
				else
					return "scorpio";
			break;
			case 11:
				if ($day > 30)
					throw new Exception('In november, day should be no more than 30.');
				if ($day <=21)
					return "scorpio";
				else
					return "sagittarius";
			break;
			case 12:
				if ($day > 31)
					throw new Exception('In december, day should be no more than 31.');
				if ($day <=22)
					return "sagittarius";
				else
					return "capricorn";
			break;
		}
	}
}

//// Tests
//echo getZodiacSign();echo "<br />";
//
//$sorens = "02-10-1965 08:00";
//echo getZodiacSign($sorens);echo "<br />";
//
//$a = "18-03-1964 08:00";
//echo getZodiacSign($a);echo "<br />";
//
//$f = "17-09-1990 08:00";
//echo getZodiacSign($f);echo "<br />";

?>